function lengthOfLastWord(s: string): number {
    /**
     * 找到最后一个空格，end
     * 从end往前找到出现的第一个空格start
     * 
     */
    // console.log(s.substring(s.lastIndexOf(' ')));
    // return s.substring(s.lastIndexOf(' ')+1).length;
    if (s.length === 1) {
        return 1;
    }
    let end = s.length - 1;
    while (end >= 0 && s[end] === ' ') {
        end--;
    }
    let start = end;
    while (start >= 0 && s[start] !== ' ') {
        start--;
    }
    return end - start;
};
// let s = "   fly me   to   the moon ";
// let s = "Hello World";
// let s = "luffy is still joyboy"
let s = 'a '
console.log(lengthOfLastWord(s));